<script setup>
import { ref, onMounted } from 'vue'
import { Delete } from '@element-plus/icons-vue'
import { rsDelete, get_list } from '@/views/enterprise/service/method'
import loading from '@/views/enterprise//service/state.js' // loding状态管理文件
import chat from '@/views/enterprise/service/chat_fun'
import { useEnterpriseStore } from '@/stores'

const enterpriseStore = useEnterpriseStore()
const parsedData = ref([])
const getParsedData = async () => {
  const initialList = await get_list() //获取列表数据
  initialList.forEach((item) => {
    const str = item.analyseResult
    const data = JSON.parse(str)
    const newItem = {
      realName: item.name,
      informationId: item.informationId,
      ...data.result // 将data.result中的所有属性复制到newItem中
    }
    parsedData.value.push(newItem)
  })
}
onMounted(() => {
  getParsedData()
})
/*删除信息*/
const deleteRS = async (id, name) => {
  await rsDelete(id)
  //删除sortedList对应元素
  const index = parsedData.value.findIndex((item) => item.informationId === id)
  if (index !== -1) {
    // 删除找到的元素
    parsedData.value.splice(index, 1)
  }
  // 删除知识库里面的文件
  try {
    let filenames = [`${id}_${name}.txt`]
    chat.deleteDocs(enterpriseStore.knowledge_base, filenames)
  } catch (error) {
    console.error('删除信息时发生错误:', error)
    ElMessage({ type: 'error', message: '知识库文件删除失败' })
  }
}
</script>

<template>
  <el-table :data="parsedData" border v-loading="loading">
    <el-table-column label="基本信息" width="200px">
      <template v-slot="scope">
        <div class="basicBox">
          <span class="basic-tag">姓名: </span>
          <span class="basic-content">{{
            scope.row.realName || scope.row.name
          }}</span>
        </div>
        <div class="basicBox">
          <span class="basic-tag">年龄: </span>
          <span class="basic-content">{{
            scope.row.age || scope.row.age_inf + '(推测)'
          }}</span>
        </div>
        <div class="basicBox">
          <span class="basic-tag">性别: </span>
          <span class="basic-content">
            {{ scope.row.gende || scope.row.gender_inf + '(推测)' }}</span
          >
        </div>
        <div class="basicBox">
          <span class="basic-tag">民族: </span>
          <span class="basic-content">{{ scope.row.race }}</span>
        </div>
        <div class="basicBox">
          <span class="basic-tag">婚姻状态: </span>
          <span class="basic-content"> {{ scope.row.marital_status }}</span>
        </div>
        <div class="basicBox">
          <span class="basic-tag">籍贯/户口: </span>
          <span class="basic-content">{{
            scope.row.hometown_address || scope.row.hukou_address
          }}</span>
        </div>
        <div class="basicBox">
          <span class="basic-tag">政治面貌: </span>
          <span class="basic-content"> {{ scope.row.polit_status }}</span>
        </div>

        <div class="basicBox">
          <span class="basic-tag">求职意向: </span>
          <span class="basic-content">
            {{ scope.row.apply_job || scope.row.expect_job }}</span
          >
        </div>
        <div class="basicBox">
          <span class="basic-tag">工作经验: </span>
          <span class="basic-content"
            >{{
              scope.row.work_year_norm ||
              scope.row.work_year ||
              work_year_inf + '(推测)'
            }}(年)</span
          >
        </div>
      </template>
    </el-table-column>
    <el-table-column label="教育背景" width="200px">
      <template v-slot="scope">
        <div
          v-for="(item, index) in scope.row.education_objs"
          :key="index"
          class="edu-expBox"
        >
          <sapn class="edu-tag">
            {{ item.start_date }} — {{ item.end_date }}
          </sapn>
          <span class="edu-tag">
            {{ item.edu_college }}
          </span>
          <sapn class="edu-tag">
            {{ item.edu_major + '—' + item.edu_dgree }}
          </sapn>
        </div>
      </template>
    </el-table-column>
    <el-table-column label="工作经历&实习经历&实践经历" width="330px">
      <template v-slot="scope">
        <div
          v-for="(item, index) in scope.row.job_exp_objs"
          :key="index"
          class="job-expBox"
        >
          <div class="job-content">
            <span class="job-tag">时间: </span>
            {{
              item.start_date +
              '&nbsp;&nbsp;—&nbsp;&nbsp;' +
              item.end_date +
              '&nbsp;&nbsp;—&nbsp;&nbsp;' +
              item.job_duration
            }}
          </div>
          <div class="job-cpytBox job-content">
            <span class="job-tag">公司&职位: </span>
            {{ item.job_cpy + '&nbsp;&nbsp;—&nbsp;&nbsp;' + item.job_position }}
          </div>
          <div class="job-content">
            <span class="job-tag">工作内容: </span>
            {{ item.job_content }}
          </div>
        </div>
        <!-- 学校实践经历 -->
        <div
          v-for="(item, index) in scope.row.social_exp_objs"
          :key="index"
          class="job-expBox"
        >
          <div class="job-timeBox">
            <span class="job-tag">时间: </span>
            {{
              item.start_date + '~' + item.end_date + '共' + item.job_duration
            }}
          </div>
          <div class="job-cpytBox">
            <span class="job-tag">单位&职位: </span>
            {{ item.job_cpy + '~' + item.job_position }}
          </div>
          <div class="job-contentBox">
            <span class="job-tag">工作内容: </span>
            {{ item.job_content }}
          </div>
        </div>
      </template>
    </el-table-column>
    <el-table-column label="技能&证书&奖励" width="200px">
      <template v-slot="scope">
        <div class="title-box">
          <span class="tag">证书名称 </span>
          <span class="tag">类型 </span>
        </div>
        <div v-for="(item, index) in scope.row.all_cert_objs" :key="index">
          <sapn class="tag">{{ item.cert_name }}</sapn>
          <span class="tag" v-if="item.cert_type === 'certificate'">证书</span>
          <span class="tag" v-else-if="item.cert_type === 'award'">奖项</span>
        </div>
        <div class="title-box">
          <span class="tag">技能名称 </span>
          <span class="tag">技能水平 </span>
        </div>
        <div v-for="(item, index) in scope.row.skills_objs" :key="index">
          <sapn class="tag">{{ item.skills_name }}</sapn
          ><span class="tag">{{ item.skills_level }}</span>
        </div>
      </template></el-table-column
    >
    <el-table-column label="自我评价" prop="cont_my_desc" width="180px">
    </el-table-column>
    <el-table-column label="操作" align="right">
      <template #default="scope">
        <div class="resume_integrity">
          <span class="tag">简历完整度</span>
          <span class="data">{{ scope.row.resume_integrity }}%</span>
        </div>
        <el-button
          :icon="Delete"
          size="large"
          @click="deleteRS(scope.row.informationId, scope.row.realName)"
        ></el-button>
      </template>
    </el-table-column>
    <template #empty>
      <el-empty description="暂无数据!!!" />
    </template>
  </el-table>
</template>
<style scoped>
.el-table {
  width: 100%;
  height: 700px;
  border-radius: 10px;
  overflow-y: scroll;
}
.basicBox {
  display: flex;
  width: 200px;
  height: 50px;
  color: rgba(45, 76, 100, 0.5);
  font-size: 18px;
  font-weight: bold;
  /* border: 1px solid black; */
  .basic-tag {
    display: inline-block;
    width: 100px;
    height: 50px;
  }
  .basic-content {
    width: 100px;
    height: 50px;
  }
}

.edu-expBox {
  display: inline-block;
  width: 100%;
  padding: 10px;
  margin: 0;
  font-size: 18px;
  border-bottom: 1px solid rgb(137, 139, 174);
  .edu-tag {
    display: block;
    width: 200px;
    min-height: 40px;
  }
}
.job-expBox {
  width: 100%;
  margin-top: 30px;
  .job-content {
    margin-top: 5px;
  }
  .job-cpytBox {
    color: blue;
  }
  .job-tag {
    font-size: 18px;
  }
}
.title-box {
  width: 100%;
  margin-top: 20px;
  font-size: 20px;
}
.tag {
  display: inline-block;
  width: 50%;
  text-align: center;
}
.resume_integrity {
  width: 100%;
  margin-bottom: 50px;
  .tag {
    width: 80px;
  }
  .data {
    font-size: 18px;
  }
}
</style>
